package com.project2.service;

import com.project2.bean.po.MarketChannel;
import com.project2.bean.po.MarketOrder;
import com.project2.bean.po.MarketOrderExample;
import com.project2.bean.po.MarketUser;
import com.project2.bean.vo.UserIndex;
import com.project2.mapper.MarketOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：HsDsg
 * @date ：2022/8/15 13:23
 * @description：TODO
 */
@Service
public class UserIndexServiceImpl implements UserIndexService {

    @Autowired
    MarketOrderMapper orderMapper;

    @Override
    public UserIndex selectUserOrder(MarketUser user) {
//        List<MarketChannel> marketChannels = orderMapper.selectAll();
        Integer id = user.getId();
        UserIndex userIndex = new UserIndex();
        int uncomment=0;
          int unpaid=0;
          int unrecv=0;
         int unship =0;
        MarketOrderExample marketOrderExample = new MarketOrderExample();
        MarketOrderExample.Criteria criteria = marketOrderExample.createCriteria();
        criteria.andUserIdEqualTo(id)
                .andDeletedEqualTo(false);
        List<MarketOrder> marketOrders = orderMapper.selectByExample(marketOrderExample);


//        List<MarketOrder> marketOrders = orderMapper.selectUserOrderState(user.getId());

        if (marketOrders.size()==0){
            return userIndex;
        }

        for (MarketOrder marketOrder : marketOrders) {
            //待评价订单数量
            Short comments = marketOrder.getComments();

            //订单状态
            Short orderStatus = marketOrder.getOrderStatus();

            if (orderStatus==101){
                unpaid++;
            }else if (orderStatus==201){
                unship++;
            }else if (orderStatus==301){
                unrecv++;
            }else if (comments!=0){
                uncomment+=comments;
            }
        }
        userIndex.setUncomment(uncomment);
        userIndex.setUnpaid(unpaid);
        userIndex.setUnrecv(unrecv);
        userIndex.setUnship(unship);

        return userIndex;
    }
}
